/*
 * @Description:路由文件
 * @Author: huahua
 * @Date: 2021-11-02 17:22:04
 * @LastEditTime: 2021-11-04 11:21:20
 * @LastEditors: huahua
 */
import Vue from "vue";
import VueRouter from "vue-router";
// import cookie from "@/utils/cookie";
// import { message } from "ant-design-vue";
Vue.use(VueRouter);
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err);
};
const routes = [
	{
		path: "/",
		redirect: "/login",
	},
	{
		path: "/login",
		name: "login",
		component: () => import("../views/login"),
	},
	{
		path: "/register",
		name: "register",
		component: () => import("../views/login/register.vue"),
	},
	// {
	//   path: "*",
	//   component: () => import("../views/404")
	// }
];

const router = new VueRouter({
	base: process.env.BASE_URL,
	routes,
});

/**
 * 路由拦截
 * 权限验证
 */
// router.beforeEach(function(to, from, next) {
//   if (to.meta.needLogin) {
//     //页面是否登录
//     if (localStorage.getItem("phone")) {
//       //本地存储中是否有token(sid)数据
//       next(); //表示已经登录
//     } else {
//       // 提示登录
//       message.error("请先登录！");
//       //next可以传递一个路由对象作为参数 表示需要跳转到的页面
//       location.href = localStorage.getItem("loginUrl");
//     }
//   } else {
//     //表示不需要登录
//     next(); //继续往后走
//   }
// });

export default router;
